<template>
  <div class="input-section">
    <el-form :model="queryForm" :inline="true">
      <el-form-item label="用户ID">
        <el-input v-model="queryForm.userid" placeholder="请输入用户ID" clearable></el-input>
      </el-form-item>
      <el-form-item label="简历编号">
        <el-input v-model="queryForm.resumeNumber" placeholder="请输入简历编号" clearable></el-input>
      </el-form-item>
      <el-form-item label="语言">
        <el-select v-model="queryForm.lang" placeholder="请选择语言" @change="handleLangChange">
          <el-option :value="1" label="中文"></el-option>
          <el-option :value="2" label="英文"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery" :loading="loading">查询简历</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { reactive, defineProps, defineEmits } from 'vue'
import { ElMessage } from 'element-plus'

interface QueryForm {
  resumeNumber: string
  lang: number
  userid: string
}

const props = defineProps<{
  loading: boolean
}>()

const emit = defineEmits<{
  query: [form: QueryForm]
  clear: []
}>()

const queryForm = reactive<QueryForm>({
  resumeNumber: '',
  lang: 1,
  userid: ''
})

const handleQuery = () => {
  if (queryForm.userid && queryForm.resumeNumber) {
    ElMessage.warning('请只选择用户ID或简历编号其中一种方式进行查询')
    return
  }
  emit('clear')
  emit('query', queryForm)
}

const handleLangChange = () => {
  emit('clear')
}
</script>

<style scoped>
.input-section {
  margin-bottom: 20px;
}

.el-select {
  width: 100%;
  min-width: 200px;
}

.el-select .el-input {
  width: 100%;
}

.el-select-dropdown {
  max-width: none;
}
</style>